﻿<UserControl x:Class="UCL.Powersource.Views.ReportingView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:pui="clr-namespace:PowersourceUIToolkit;assembly=PowersourceUIToolkit"
             xmlns:as="clr-namespace:UCL.Powersource.Views.Analysis"
             xmlns:vs="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.11.0"
             Background="{DynamicResource {x:Static vs:VsBrushes.ToolWindowBackgroundKey}}"
             Foreground="{DynamicResource {x:Static vs:VsBrushes.WindowTextKey}}"
             mc:Ignorable="d" 
             d:DesignHeight="404" d:DesignWidth="700">
    <!--<ScrollViewer  Name="scroller" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Left" VerticalContentAlignment="Top" HorizontalScrollBarVisibility="Visible"
                   SizeChanged="scroller_SizeChanged_1" CanContentScroll="False">-->
    <UserControl.Resources>
        <ResourceDictionary >
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="VSLikeStyles.xaml"/>
                <ResourceDictionary Source="DefaultResourceDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>


    </UserControl.Resources>
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup Name="StatisticViewModelTypeVisualStates_Team">
            <VisualState Name="SingleTeam">
                <Storyboard >
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="lbSelectableTfsTeamProjectConfigurations" 
                                                       Storyboard.TargetProperty="Visibility"
                                                   Duration="0"
                                                   >
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="cxActiveTfsTeamProjectConfiguration" 
                                                       Storyboard.TargetProperty="Visibility"
                                                   Duration="0">
                        <DiscreteObjectKeyFrame KeyTime="0"  Value="{x:Static Visibility.Visible}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>

                </Storyboard>
            </VisualState>
            <VisualState Name="MultipleTeams">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames  Duration="0" Storyboard.TargetName="lbSelectableTfsTeamProjectConfigurations" 
                                                       Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="cxActiveTfsTeamProjectConfiguration" 
                                                       Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
            <VisualStateGroup.Transitions>
                <VisualTransition To="SingleTeam">
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="lbSelectableTfsTeamProjectConfigurations" Storyboard.TargetProperty="(ListBox.LayoutTransform).(ScaleTransform.ScaleY)" To="0" Duration="0:0:0.5"/>
                        <DoubleAnimation Storyboard.TargetName="cxActiveTfsTeamProjectConfiguration" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:0.5"/>
                    </Storyboard>
                </VisualTransition>
                <VisualTransition To="MultipleTeams" GeneratedDuration="0:0:0.01">
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="lbSelectableTfsTeamProjectConfigurations" Storyboard.TargetProperty="(ListBox.LayoutTransform).(ScaleTransform.ScaleY)" From="0" To="1" Duration="0:0:0.5"/>
                        <DoubleAnimation Storyboard.TargetName="cxActiveTfsTeamProjectConfiguration" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.5"/>
                    </Storyboard>
                </VisualTransition>
            </VisualStateGroup.Transitions>

        </VisualStateGroup>
        <VisualStateGroup Name="StatisticViewModelTypeVisualStates_TimeFrame">
            <VisualState Name="SingleTimeFrame">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="lbSelectableTimeFrames" 
                                                       Storyboard.TargetProperty="Visibility"
                                                       >
                        <DiscreteObjectKeyFrame  KeyTime="0" Value="{x:Static Visibility.Collapsed}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="cxActiveTimeFrame" 
                                                       Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
            <VisualState Name="MultipleTimeFrames">
                <Storyboard >
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="lbSelectableTimeFrames" 
                                                       Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="cxActiveTimeFrame" 
                                                       Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>

                </Storyboard>
            </VisualState>
            <VisualStateGroup.Transitions>
                <VisualTransition To="SingleTimeFrame">
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="lbSelectableTimeFrames" Storyboard.TargetProperty="(ListBox.LayoutTransform).(ScaleTransform.ScaleY)" To="0" Duration="0:0:0.5"/>
                        <DoubleAnimation Storyboard.TargetName="cxActiveTimeFrame" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:0.5"/>
                    </Storyboard>
                </VisualTransition>
                <VisualTransition To="MultipleTimeFrames">
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="lbSelectableTimeFrames" Storyboard.TargetProperty="(ListBox.LayoutTransform).(ScaleTransform.ScaleY)" From="0" To="1" Duration="0:0:0.5"/>
                        <DoubleAnimation Storyboard.TargetName="cxActiveTimeFrame" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.5"/>
                    </Storyboard>
                </VisualTransition>
            </VisualStateGroup.Transitions>
        </VisualStateGroup>
        <VisualStateGroup Name="StatisticViewModelIsConsumingActiveStatistic">
            <VisualState Name="IsConsumingActiveStatistic">
                <Storyboard  >
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="lbSelectableStatistics" 
                                                       Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="cxActiveStatistic" 
                                                       Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
            <VisualState Name="NotIsConsumingActiveStatistic">
                <Storyboard Duration="0:0:0.1">
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="lbSelectableStatistics" 
                                                       Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="cxActiveStatistic" 
                                                       Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
            <VisualStateGroup.Transitions>
                <VisualTransition To="IsConsumingActiveStatistic">
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="lbSelectableStatistics" Storyboard.TargetProperty="(ListBox.LayoutTransform).(ScaleTransform.ScaleY)" To="0" Duration="0:0:0.5"/>
                        <DoubleAnimation Storyboard.TargetName="cxActiveStatistic" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:0.5"/>
                    </Storyboard>
                </VisualTransition>
                <VisualTransition To="NotIsConsumingActiveStatistic">
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="lbSelectableStatistics" Storyboard.TargetProperty="(ListBox.LayoutTransform).(ScaleTransform.ScaleY)" From="0" To="1" Duration="0:0:0.5"/>
                        <DoubleAnimation Storyboard.TargetName="cxActiveStatistic" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.5"/>
                    </Storyboard>
                </VisualTransition>
            </VisualStateGroup.Transitions>
        </VisualStateGroup>
        <VisualStateGroup Name="StatisticViewModelIsConsumingNormalizedValues">
            <VisualState Name="IsConsumingNormalizedValues">
                <Storyboard  >
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="IsNormalized" 
                                                       Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
            <VisualState Name="NotIsConsumingNormalizedValues">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="IsNormalized" 
                                                       Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
            <VisualStateGroup.Transitions>
                <VisualTransition To="IsConsumingNormalizedValues">
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="IsNormalized" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:0.5"/>
                    </Storyboard>
                </VisualTransition>
                <VisualTransition To="NotIsConsumingNormalizedValues">
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="IsNormalized" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.5"/>
                    </Storyboard>
                </VisualTransition>
            </VisualStateGroup.Transitions>
        </VisualStateGroup>
        <VisualStateGroup Name="IsCalculatingVisualStates">
            <VisualState Name="IsCalculating">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="bdStatistics" 
                                                       Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="bdCalculating" 
                                                       Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
            <VisualState Name="NotIsCalculating">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="bdStatistics" 
                                                       Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="bdCalculating" 
                                                       Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
            <VisualStateGroup.Transitions>
                <VisualTransition To="IsCalculating">
                    <Storyboard>
                        <!--<DoubleAnimation Storyboard.TargetName="bdStatistics" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:0.5"/>-->
                    </Storyboard>
                </VisualTransition>
                <VisualTransition To="NotIsCalculating">
                    <Storyboard>
                        <!--<DoubleAnimation Storyboard.TargetName="bdStatistics" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.5"/>-->
                    </Storyboard>
                </VisualTransition>
            </VisualStateGroup.Transitions>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Grid>


        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <StackPanel Orientation="Horizontal" Background="{DynamicResource {x:Static vs:VsBrushes.CommandBarMenuBackgroundGradientKey}}" HorizontalAlignment="Stretch">
            <ComboBox Name="cbAvailableReportingContextCollection" DisplayMemberPath="Label" 
                      SelectedItem="{Binding CurrentReportingContext,Mode=TwoWay}"
                      ItemsSource="{Binding AvailableReportingContextCollection}"
                       IsReadOnly="True" IsEditable="True"
                     />
            <Button Name="CreateNameDialog" Click="RequestNewContextName" Style="{StaticResource DefaultButtonStylePowersource}">NEW REPORTING CONTEXT</Button>
            <Button Name="RequestDeleteCurrentReportingContext" Style="{StaticResource DefaultButtonStylePowersource}">DELETE CURRENT REPORTING CONTEXT</Button>
            <Button Name="RequestForceRecalculate" Style="{StaticResource DefaultButtonStylePowersource}">FORCE RECALCULATION</Button>

        </StackPanel>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Background="{DynamicResource {x:Static vs:VsBrushes.CommandBarMenuBackgroundGradientKey}}">
            <Button Name="BackToMain" Style="{StaticResource DefaultButtonStylePowersource}">BACK</Button>
            <Button Name="Debug" Click="Debug_Click_1">-</Button>
        </StackPanel>

        <Expander Grid.Row="1" IsEnabled="{Binding CurrentReportingContextExpandable}" IsExpanded="{Binding CurrentReportingContextExpanded}" Header="{Binding CurrentReportingInfoString}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
            <Grid>
                <StackPanel x:Name="spTeamProjectConfiguration"  HorizontalAlignment="Left"
                     Margin="5,0,5,0" Width="200"
                    Height="150"
                     >
                    <TextBlock Text="Select teams to be used in statistics"/>
                    <ListBox 
                x:Name="lbSelectableTfsTeamProjectConfigurations"
                     ItemsSource="{Binding CurrentReportingContext.SelectableTfsTeamProjectConfigurations}"
                     SelectionMode="Multiple" 
                        SelectionChanged="lbSelectableTfsTeamProjectConfigurations_SelectionChanged_1"
                        
                     pui:HierarchicallySynchronizedLists.SynchronizedSelectedItems="{Binding CurrentReportingContext.SelectableTfsTeamProjectConfigurations}"
                    MaxHeight="125"
                     >
                        <ListBox.LayoutTransform>
                            <ScaleTransform ScaleX="1" ScaleY="1" />
                        </ListBox.LayoutTransform>
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Label}"/>
                            </DataTemplate>
                        </ListBox.ItemTemplate>

                    </ListBox>
                    <ComboBox Name="cxActiveTfsTeamProjectConfiguration" DisplayMemberPath="Label" 
                      SelectedItem="{Binding CurrentReportingContext.ActiveTfsTeamProjectConfiguration,Mode=TwoWay}"
                      ItemsSource="{Binding CurrentReportingContext.AvailableTfsTeamProjectConfigurations}"
                       Visibility="Collapsed"
                               IsReadOnly="True" IsEditable="True"
                              />
                </StackPanel>
                <StackPanel x:Name="spTimeFrame" HorizontalAlignment="Left" Margin="210,0,0,0" Width="200"
                    Height="150">
                    <TextBlock Text="Select sprint or release to be shown"/>
                    <ListBox ItemsSource="{Binding CurrentReportingContext.SelectableTimeFrames}"
                             Name="lbSelectableTimeFrames"
                         SelectionMode="Multiple" 
                         pui:HierarchicallySynchronizedLists.SynchronizedSelectedItems="{Binding CurrentReportingContext.SelectableTimeFrames}"
                         MaxHeight="125"
                         >
                        <ListBox.LayoutTransform>
                            <ScaleTransform ScaleX="1" ScaleY="1" />
                        </ListBox.LayoutTransform>
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Label}"/>
                            </DataTemplate>
                        </ListBox.ItemTemplate>

                    </ListBox>
                    <ComboBox Name="cxActiveTimeFrame" DisplayMemberPath="Label" 
                      SelectedItem="{Binding CurrentReportingContext.ActiveTimeFrame,Mode=TwoWay}"
                      ItemsSource="{Binding CurrentReportingContext.AvailableTimeFrames}"
                      Visibility="Collapsed"
                               IsReadOnly="True" IsEditable="True"
                              />
                </StackPanel>

                <StackPanel x:Name="spStatistic" HorizontalAlignment="Left" Margin="415,0,0,0" Width="200"
                    Height="150">
                    <TextBlock Text="Select statistic to be shown"/>
                    <ListBox ItemsSource="{Binding CurrentReportingContext.SelectableStatistics}"
                         SelectionMode="Multiple" 
                         pui:HierarchicallySynchronizedLists.SynchronizedSelectedItems="{Binding CurrentReportingContext.SelectableStatistics}"
                         MaxHeight="125"
                             Name="lbSelectableStatistics"
                         >
                        <ListBox.LayoutTransform>
                            <ScaleTransform ScaleX="1" ScaleY="1" />
                        </ListBox.LayoutTransform>
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Label}" ToolTip="{Binding Description}"/>
                            </DataTemplate>
                        </ListBox.ItemTemplate>

                    </ListBox>
                    <ComboBox Name="cxActiveStatistic" DisplayMemberPath="Label" 
                      SelectedItem="{Binding CurrentReportingContext.ActiveStatistic,Mode=TwoWay}"
                      ItemsSource="{Binding CurrentReportingContext.CurrentRegisteredStatistics}"
                      Visibility="Collapsed"
                              IsReadOnly="True" IsEditable="True"
                              />
                </StackPanel>
            </Grid>
        </Expander>
        <StackPanel Orientation="Horizontal" Grid.Row="2">
            <ComboBox ItemsSource="{Binding AvailableStatisticViewModelCollection}" SelectedItem="{Binding CurrentStatisticViewModel, Mode=TwoWay}" DisplayMemberPath="Label" MinWidth="200" Text="Choose view..." IsReadOnly="True" IsEditable="True"/>
            <CheckBox Name="IsNormalized" IsChecked="{Binding CurrentReportingContext.ShowNormalized,Mode=TwoWay}" Content="Normalized Values" VerticalAlignment="Center" Margin="5,0"/>
        </StackPanel>
        
        <Border Name="bdStatistics" Grid.Row="3" Margin="0,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <!--<Border Name="svStatistics" BorderBrush="Bisque" BorderThickness="2" ></Border>-->

        </Border>
        <Border Name="bdCalculating" Grid.Row="3" Margin="0,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                Background="{DynamicResource {x:Static vs:VsBrushes.ToolWindowBackgroundKey}}" Visibility="Collapsed">
            <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                <TextBlock Text="{Binding CurrentAction_SMQ}" HorizontalAlignment="Center" />
                <TextBlock Text="{Binding CurrentActionMessage_SMQ}" HorizontalAlignment="Center" />
                <TextBlock Text="{Binding CurrentAction_RMQ}" HorizontalAlignment="Center" />
                <TextBlock Text="{Binding CurrentActionMessage_RMQ}" HorizontalAlignment="Center" />
                <ProgressBar Minimum="0" Maximum="{Binding CurrentActionProgress_Max}" Value="{Binding CurrentActionProgress_Value}" MaxWidth="200" HorizontalAlignment="Center"  MinWidth="200" MinHeight="20"/>
            </StackPanel>

        </Border>

    </Grid>
    <!--</ScrollViewer>-->
</UserControl>
